#include "savepicture.h"
#include "ui_savepicture.h"
#include "mypaint.h"
#include <QMessageBox>

SavePicture::SavePicture(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SavePicture)
{
    ui->setupUi(this);
    setFixedSize(300,300);
    setWindowTitle("另存为");
    ui->jpglabel1->setPixmap(QPixmap(":/images/jpge-fill.png").scaled(50,50));
    ui->pnglabel2->setPixmap(QPixmap(":/images/png-fill.png").scaled(50,50));
    ui->giflabel2->setPixmap(QPixmap(":/images/bmp-fill.png").scaled(50,50));
    ui->jpglabel->installEventFilter(this);
    ui->pnglabel->installEventFilter(this);
    ui->giflabel->installEventFilter(this);

}

SavePicture::~SavePicture()
{
    delete ui;
}

bool SavePicture::eventFilter(QObject *watched, QEvent *event)
{
    if(event->type() == QEvent::MouseButtonPress)
    {
        //转换为鼠标事件
        QMouseEvent* mouseevent = static_cast<QMouseEvent*>(event);
        if(mouseevent->button() == Qt::LeftButton)
        {
            if(watched == ui->jpglabel)
            {
                emit savejpg();
                this->close();
                return true;
            } else if (watched == ui->pnglabel) {
                emit savepng();
                this->close();
                return true;
            } else if (watched == ui->giflabel) {
                emit savegif();
                this->close();
                return true;
            }
        }
    }

}
